package com.gl.file;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class FileRead{
	
	public static String readUserConfig(String fileUrl) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(
				new FileInputStream(fileUrl), "UTF-8"));
		StringBuffer xmlBuffer = new StringBuffer();
		String read = "";
		while ((read = br.readLine()) != null) {
			xmlBuffer.append(read.trim());
		}
		System.out.println("xmlBuffer:" + xmlBuffer.toString());
		return xmlBuffer.toString();
	}

//	public static void main(String[] args) throws Exception {
//		String fileUrl = "userConfig.json";
//		BufferedReader br = new BufferedReader(new InputStreamReader(
//				new FileInputStream(fileUrl), "UTF-8"));
//		StringBuffer xmlBuffer = new StringBuffer();
//		String read = "";
//		while ((read = br.readLine()) != null) {
//			xmlBuffer.append(read.trim());
//		}
//		System.out.println("xmlBuffer:" + xmlBuffer.toString());
//		
//	}
	
	public static void main(String[] args) throws Exception {
		 String fileUrl = "userConfig.txt";
		 FileWriter fw = new FileWriter(fileUrl);
		 Map<String, String> map = new HashMap<String, String>();
		 map.put("id", "111");
		 map.put("name", "gaolei");
		 System.out.println(map.toString());
		 fw.write(map.toString());
		 fw.close();
		 System.out.println("****************读取文件***************");
		 System.out.println( FileRead.readUserConfig(fileUrl) );
	}
}
